<?php
/**
 * Created by PhpStorm.
 * User: chennan
 * Date: 2017/12/4
 * Time: 19:14
 */

namespace common\business\task;


use common\business\DbHandler;
use common\models\Task;
use common\result\ActionResult;

class TaskApiHandler extends DbHandler
{
    /**
     * @param $obj Task
     * @return ActionResult
     */
    public function createTask($obj){
        return $this->create($obj);
    }

    /**
     * @param Task $newObj
     * @param Task $oldObj
     * @return ActionResult
     */
    public function updateTask($newObj, $oldObj = null){
        if (!$oldObj){
            $oldObj = Task::findOne([
                'id' => $newObj->id,
            ]);
        }
        return $this->update($newObj, $oldObj, [
            'type',
            'priority',
            'key',
            'from_system',
            'request_data',
            'response_data',
            'memo',
            'is_synchronization',
            'status',
            'next_run_date',
            'suspend_times',
            'retry_times',
            'started_at',
            'stopped_at',
            'total_number',
            'finished_number',
            'finish_rate',
            'created_by',
//            'created_at',
            'updated_by',
//            'updated_at',
        ]);
    }

}